module Main where

import Data.Graph.Inductive.Tree (UGr)

import System.CPUTime (getCPUTime)
import System (getArgs)

import List (length,tails)
import Alg (findMaxIndSet)
import Dot

inputOutput sourceFile = do
    putStr "Reading source file...\n\n"
    graphDotString <- readFile sourceFile
    let graph = getGraph graphDotString
    putStr "Search started,\n\n"
    beginTime <- getCPUTime
    let maxIndSet = findMaxIndSet graph
    putStr $ concat ["Largest Independent Set is found:",show maxIndSet,"\n\n"]
    endTime <- getCPUTime
    putStr $ concat ["Algotithm execution time: ", show ((endTime - beginTime) `div` 1000000000),"ms"]
    writeFile "result.dot" $ showGraphInDot graph maxIndSet

main :: IO ()
main = do     
    args <- getArgs
    case (length args) of
        0 -> putStr "Please, specify the source DOT file."
        1 -> if (elem ".dot" (tails $ head args)) 
		     then inputOutput $ head args
			 else putStr "*.dot file is required."
        _ -> putStr "Too much parameters! Please, specify the source DOT file."